import React, { Component } from 'react';

// propTypes校验传递的值
import propTypes from 'prop-types';

class XjjItem extends Component {

    constructor(props) {
        super(props)
        this.handleClick = this.handleClick.bind(this)
    }

    shouldComponentUpdate(nextProps, nextState) {
        if (nextProps.content !== this.props.content) {
            return true
        } else {
            return false
        }
    }

    render() {
        console.log('child-render');
        return (
            <>
                <li onClick={this.handleClick}>
                    {this.props.avname}为你服务-
                    {this.props.content}
                </li>
            </>
        );
    }

    handleClick() {
        this.props.deleteItem(this.props.index)
    }
}

XjjItem.propTypes = {
    avname: propTypes.string.isRequired,
    content: propTypes.string,
    index: propTypes.number,
    deleteItem: propTypes.func
}

// 为传递的数据添加设置默认值
XjjItem.defaultProps = {
    avname: "二号技师"
}

export default XjjItem;